import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { ItemData } from "../../../resource/info/ItemData";
import { MountConfig } from "../../../resource/MountConfig";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { MountsCache } from "../../../cache/MountsCache";
import { DateParser } from "../../../../common/tools/DateParser";
import { ClockManager } from "../../../manager/ClockManager";
import { ToolTipItem } from "../../../../../com/mui/manager/ToolTipItem";
import { Cache } from "../../../cache/Cache";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { PetProcessBar } from "../../pet/PetProcessBar";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SpMountTip } from "../../mounts/mount/SpMountTip";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { DataEvent } from "../../../events/DataEvent";
import { Global } from "../../../../../com/gengine/global/Global";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { ExpAddEffect } from "../../effect/ExpAddEffect";
import { ExpAddEffectInfo } from "../../../resource/info/ExpAddEffectInfo";
import { SGuildPastureExp } from "../../../../../Message/Public/SGuildPastureExp";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class GuildPastureView
    
    export  class GuildPastureView extends View
    {
        constructor()
        {
            super();
            this._tPoint = new Object /* flash.geom.Point */();
            this.layer = LayerManager.uiLayer;
            this.init();
            this.stageResize();
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            this._secTimer = new SecTimer();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onCheckHandler);
            this._secTimer.start();
            return;
        }

        public set isMore(arg1: Boolean)
        {
            this._isMore = arg1;
            if (this._isMore) 
            {
                this._extBtn.styleName = "SubBtn2";
            }
            else 
            {
                this._extBtn.styleName = "SupBtn2";
            }
            this.resetLayout(this.isMore);
            return;
        }

        public get isMore(): Boolean
        {
            return this._isMore;
        }

        public updateByMount(arg1: ItemData): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1) 
            {
                this._level = arg1.itemExInfo.mount_level;
                this._saturation = arg1.itemExInfo.feed_degree;
                if (this._saturation < 0) 
                {
                    this._saturation = 0;
                }
                this._nameTxt.text = arg1.name;
                this._levelTxt.text = this._level.toString();
                this._expBar.setValue(arg1.itemExInfo.experience, MountConfig.instance.getTotalExpByLevel(this._level + arg1.itemExInfo.mount_rein * 1000));
                this._saturationBar.setValue(this._saturation, 120);
                if (this._saturation >= 100 && this._saturation <= 119) 
                {
                    this._saturationBar.progressBarClass = ImagesConst.PurpleBar10;
                    this._saturationBar.toolTipData = Language.getStringByParam(70086, MountsCache.FULL50);
                }
                else if (this._saturation != 120) 
                {
                    this._saturationBar.progressBarClass = ImagesConst.GreenBar10;
                    this._saturationBar.toolTipData = Language.getStringByParam(70086, MountsCache.FULL100);
                }
                else 
                {
                    this._saturationBar.progressBarClass = ImagesConst.RedBar10;
                    this._saturationBar.toolTipData = Language.getStringByParam(70086, MountsCache.FULL25);
                }
                this._getExpLabelTxt.text = Language.getString(57588);
                this._getExpTxt.visible = true;
                this._spMountTip.updateInfo(arg1);
                loc1 = DateParser.strToDateNormal(arg1.itemExInfo.l_feed_dt);
                loc2 = ClockManager.instance.nowDate;
                if (!(loc1.getMonth() === loc2.getMonth()) || !(loc1.getFullYear() === loc2.getFullYear()) || !(loc1.getDate() === loc2.getDate())) 
                {
                    this._saturation = 0;
                    this._saturationBar.setValue(this._saturation, 120);
                    this._saturationBar.toolTipData = Language.getStringByParam(70086, MountsCache.FULL100);
                }
            }
            else 
            {
                this.clear();
            }
            return;
        }

        public updateGetExp(arg1: int): void
        {
            this._getExpTxt.text = arg1.toString();
            return;
        }

        /* internal  */init(): void
        {
            this._bg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bg);
            this._icon = new Object /* flash.display.Bitmap */();
            this._icon.x = -40;
            this._icon.y = -50;
            this.addChild(this._icon);
            this._activityItem = new ToolTipItem();
            this._activityItem.x = 255;
            this._activityItem.y = 35;
            this.addChild(this._activityItem);
            this._treeIcon = new Object /* flash.display.Bitmap */();
            this._activityItem.addChild(this._treeIcon);
            this.enableTree(Cache.instance.guildPasture.isInExpActivity());
            ObjCreate.createTextField(Language.getString(57587), 60, 8, 220, 20, this);
            this._nameTxt = ObjCreate.createTextField("", 97, 8, 220, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._extBtn = ObjCreate.createGButton("", 265, 5, 24, 22, this, "SubBtn2");
            this._extBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onExtBtnClickHandler);
            this._getExpLabelTxt = ObjCreate.createTextField(Language.getString(57588), 60, 35, 220, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._getExpLabelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._getExpTxt = ObjCreate.createTextField("0", 140, 35, 220, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._getExpTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._expLabelTxt = ObjCreate.createTextField(Language.getString(70028), 15, 65, 220, 20, this);
            this._expBar = new PetProcessBar(ImagesConst.GreenBar10, 152);
            this._expBar.move(65, 67);
            this._expBar.setValue(0, 0);
            this.addChild(this._expBar);
            this._levelTxt = ObjCreate.createTextField("0", 220, 63, 25, 20, this, new GTextFormat(FontUtil.stXingkaiName, 20, 15788607));
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._levelLabelTxt = ObjCreate.createTextField(Language.getString(70054), 245, 65, 22, 20, this, GlobalStyle.textFormat6);
            this._saturationLabelTxt = ObjCreate.createTextField(Language.getString(70081), 15, 98, 220, 20, this);
            this._saturationBar = new PetProcessBar(ImagesConst.YellowBar10, 152);
            this._saturationBar.move(65, 100);
            this._saturationBar.setValue(0, 0);
            this.addChild(this._saturationBar);
            this._spMountTip = new SpMountTip();
            this._spMountTip.x = 225;
            this._spMountTip.y = 85;
            this.addChild(this._spMountTip);
            LoaderHelp.addResCallBack(ResFileConst.guildPasture, this.onLodedHandler);
            return;
        }

        /* internal  */onLodedHandler(): void
        {
            this._isLoaded = true;
            this.updateBg(this.isMore);
            this._icon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildPastureMount);
            this._treeIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildPastureTree);
            return;
        }

        /* internal  */onExtBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            this.isMore = !this.isMore;
            return;
        }

        /* internal  */updateBg(arg1: Boolean): void
        {
            if (this._isLoaded) 
            {
                if (arg1) 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildPastureBg);
                }
                else 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildPastureBgSmall);
                }
            }
            return;
        }

        /* internal  */resetLayout(arg1: Boolean): void
        {
            this._expLabelTxt.visible = arg1;
            this._getExpLabelTxt.visible = arg1;
            this._getExpTxt.visible = arg1;
            this._saturationLabelTxt.visible = arg1;
            this._saturationBar.visible = arg1;
            this._spMountTip.visible = arg1;
            if (arg1) 
            {
                this._levelTxt.x = 220;
                this._levelTxt.y = 63;
                this._levelLabelTxt.x = 245;
                this._levelLabelTxt.y = 65;
                this._expBar.move(65, 67);
            }
            else 
            {
                this._levelTxt.x = 45;
                this._levelTxt.y = 38;
                this._levelLabelTxt.x = 70;
                this._levelLabelTxt.y = 40;
                this._expBar.move(95, 40);
            }
            this._levelTxt.width = 25;
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this.updateBg(arg1);
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.Event */): void
        {
            this.startDrag();
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.Event */): void
        {
            this.stopDrag();
            return;
        }

        /* internal  */onRoleMountDataChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Boolean;
            if (loc1) 
            {
                this.updateEquipMount();
            }
            return;
        }

        /* internal  */onBackPackChangeHandler(arg1: Object=null): void
        {
            this.updateEquipMount();
            return;
        }

        /* internal  */updateEquipMount(): void
        {
            this.updateByMount(Cache.instance.pack.mountsPackCache.equipEdMount);
            return;
        }

        /* internal  */onStageResizeHandler(arg1: DataEvent): void
        {
            this.stageResize();
            return;
        }

        /* internal  */stageResize(): void
        {
            x = Global.stage.stageWidth - width + 60;
            y = 180 + 20 * Global.stage.stageHeight / 1000;
            return;
        }

        /* internal  */enableTree(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._activityItem.toolTipData = Language.getString(57593);
                this._treeIcon.filters = [];
            }
            else 
            {
                this._activityItem.toolTipData = null;
                this._treeIcon.filters = [FilterConst.colorFilter];
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.updateGetExp(0);
            Cache.instance.guildPasture.clearExp();
            this._secTimer.stop();
            Dispatcher.removeEventListener(EventName.Role_MountDataChange, this.onRoleMountDataChangeHandler);
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResizeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.onBackPackChangeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.BackpackDataChange, this.onBackPackChangeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.RolePackItemsChange, this.onBackPackChangeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.GuildPastureExpCommand, this.onGuildPastureExpCommandHandler);
            return;
        }

        /* internal  */playExpValueAddEffect(arg1: int): void
        {
            var loc1=null;
            if (this._isMore) 
            {
                this._tPoint.x = 150;
                this._tPoint.y = 35;
                loc1 = localToGlobal(this._tPoint);
            }
            else 
            {
                this._tPoint.x = 170;
                this._tPoint.y = 45;
                loc1 = localToGlobal(this._tPoint);
            }
            var loc2=new ExpAddEffect(new ExpAddEffectInfo(loc1.x, loc1.y, loc1.x, loc1.y, arg1, 1));
            loc2.playEffect();
            return;
        }

        /* internal  */onCheckHandler(arg1: SecTimer): void
        {
            var loc1=Cache.instance.guildPasture.isInExpActivity();
            if (loc1 != this._isInActivity) 
            {
                this.enableTree(loc1);
                this._isInActivity = loc1;
            }
            return;
        }

        /* internal  */clear(): void
        {
            this._nameTxt.text = Language.getString(57589);
            this._getExpLabelTxt.text = Language.getString(57590);
            this._getExpTxt.visible = false;
            this._spMountTip.updateInfo(null);
            this._expBar.setValue(0, 0);
            this._saturationBar.setValue(0, 0);
            this._levelTxt.text = "0";
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updateEquipMount();
            this._secTimer.reset();
            this._secTimer.start();
            Dispatcher.addEventListener(EventName.Role_MountDataChange, this.onRoleMountDataChangeHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResizeHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onBackPackChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.onBackPackChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.RolePackItemsChange, this.onBackPackChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.GuildPastureExpCommand, this.onGuildPastureExpCommandHandler);
            return;
        }

        /* internal  */onGuildPastureExpCommandHandler(arg1: SGuildPastureExp): void
        {
            this.playExpValueAddEffect(arg1.experience);
            this.updateGetExp(Cache.instance.guildPasture.totalExp);
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_icon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_extBtn: GButton;

        /* internal */ /* var */_getExpTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_activityItem: ToolTipItem;

        /* internal */ /* var */_treeIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_expLabelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_expBar: PetProcessBar;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelLabelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_saturationLabelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_saturationBar: PetProcessBar;

        /* internal */ /* var */_spMountTip: SpMountTip;

        /* internal */ /* var */_isMore: Boolean=true;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_saturation: int;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_isInActivity: Boolean;

        /* internal */ /* var */_getExpLabelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_tPoint: Object /* flash.geom.Point */;
    }
